@include('admin.public.head')

<div class="ibox-title">
    <h5>付款方式添加</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">付款方式名稱：</label>
            <div class="col-sm-9">
                <input type="text" name="pay_name" class="form-control"  value="{{$result->pay_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">圖片：</label>
            <div class="col-sm-9">
                <input type="file" name="pay_img" class="form-control"  value="">
                <img src="{{$result->pay_img??''}}" width="300" height="150">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/pay_type" class="btn btn-primary" >返回付款列表</a>
            </div>
        </div>
    </form>
</div>

<script>

    $('.do').click(function(){
        var form = new FormData();

        var id = $('input[name="id"]').val();
        var pay_name = $('input[name="pay_name"]').val();
        var pay_img = $('input[name="pay_img"]')[0].files[0];

        form.append("pay_name", pay_name);
        form.append("id", id);
        form.append("pay_img", pay_img);

        $.ajax({
            type: 'POST',
            url: '/pay_type_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>
